package schoolword;

public class Test6 {

        public static void main(String[] args) throws InterruptedException {
            Thread t2 = new Thread(() -> {
                for (int i = 0; i < 5; i++) {
                    System.out.println("t2");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });

            Thread t1 = new Thread(() -> {
                //t1等t2
                try {
                    Thread.sleep(500);
                    t2.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                for (int i = 0; i < 5; i++) {
                    System.out.println("t1");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });

            t1.start();
            t2.start();
            t1.join();
            System.out.println("main end");
        }
    }

